export const INCREMENT_COUNTER = 'INCREMENT_COUNTER'
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER'


export function  increment() {
    return{
        type:INCREMENT_COUNTER
    }
    
    
}

export function decrement() {
    return{
        type:DECREMENT_COUNTER
    }
}

//导出奇数加一的方法，该方法返回一个方法，包含dispatch和getState两个参数，dispatch用于action的方法，getState返回state
export function incrementIfOdd() {
    return(dispatch,getState)=>{
        const { counter } = getState()

        if(counter % 2 === 0){
            return
        }else {
            dispatch(increment())
        }

    }
}


export  function  incrementAsync(delay = 1000) {
    return dispatch =>{
        setTimeout(()=>{
            dispatch(increment())
        },delay)
    }
}